﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.Romance
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System;
using System.Collections.Generic;
using System.Linq;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem
{
  public class Romance
  {
    [SaveableField(7)]
    private readonly List<Romance.RomanticState> _romanticStateList;

    internal static void AutoGeneratedStaticCollectObjectsRomance(
      object o,
      List<object> collectedObjects)
    {
      ((Romance) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected virtual void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      collectedObjects.Add((object) this._romanticStateList);
    }

    internal static object AutoGeneratedGetMemberValue_romanticStateList(object o)
    {
      return (object) ((Romance) o)._romanticStateList;
    }

    public static List<Romance.RomanticState> RomanticStateList
    {
      get => Campaign.Current.Romance._romanticStateList;
    }

    public Romance() => this._romanticStateList = new List<Romance.RomanticState>();

    public static Hero GetCourtedHeroInOtherClan(Hero person1, Hero person2)
    {
      foreach (Hero person2_1 in person2.Clan.Lords.Where<Hero>((Func<Hero, bool>) (x => x != person2)))
      {
        if (Romance.GetRomanticLevel(person1, person2_1) >= Romance.RomanceLevelEnum.MatchMadeByFamily)
          return person2;
      }
      return (Hero) null;
    }

    public static Romance.RomanceLevelEnum GetRomanticLevel(Hero person1, Hero person2)
    {
      Romance.RomanticState romanticState = Romance.GetRomanticState(person1, person2);
      return romanticState == null ? Romance.RomanceLevelEnum.Untested : romanticState.Level;
    }

    public static Romance.RomanticState GetRomanticState(Hero person1, Hero person2)
    {
      if (Romance.RomanticStateList == null)
        return (Romance.RomanticState) null;
      foreach (Romance.RomanticState romanticState in Romance.RomanticStateList)
      {
        if (romanticState != null && (romanticState.Person1 == person1 && romanticState.Person2 == person2 || romanticState.Person1 == person2 && romanticState.Person2 == person1))
          return romanticState;
      }
      return (Romance.RomanticState) null;
    }

    internal static void EndAllCourtships(Hero forHero)
    {
      foreach (Romance.RomanticState romanticState in Romance.RomanticStateList)
      {
        if (romanticState.Person1 == forHero || romanticState.Person2 == forHero)
          romanticState.Level = Romance.RomanceLevelEnum.Ended;
      }
    }

    internal static void SetRomanticState(
      Hero person1,
      Hero person2,
      Romance.RomanceLevelEnum romanceLevelEnum)
    {
      Romance.RomanticState romanticState = Romance.GetRomanticState(person1, person2);
      if (romanticState != null)
        romanticState.Level = romanceLevelEnum;
      else
        Romance.RomanticStateList.Add(new Romance.RomanticState()
        {
          Person1 = person1,
          Person2 = person2,
          Level = romanceLevelEnum,
          ProgressToNextLevel = 0
        });
    }

    public class RomanticState
    {
      [SaveableField(0)]
      public Hero Person1;
      [SaveableField(1)]
      public Hero Person2;
      [SaveableField(2)]
      public Romance.RomanceLevelEnum Level;
      [SaveableField(3)]
      public int ProgressToNextLevel;
      [SaveableField(5)]
      public float LastVisit;
      [SaveableField(6)]
      public float ScoreFromPersuasion;

      internal static void AutoGeneratedStaticCollectObjectsRomanticState(
        object o,
        List<object> collectedObjects)
      {
        ((Romance.RomanticState) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
      }

      protected virtual void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
      {
        collectedObjects.Add((object) this.Person1);
        collectedObjects.Add((object) this.Person2);
      }

      internal static object AutoGeneratedGetMemberValuePerson1(object o)
      {
        return (object) ((Romance.RomanticState) o).Person1;
      }

      internal static object AutoGeneratedGetMemberValuePerson2(object o)
      {
        return (object) ((Romance.RomanticState) o).Person2;
      }

      internal static object AutoGeneratedGetMemberValueLevel(object o)
      {
        return (object) ((Romance.RomanticState) o).Level;
      }

      internal static object AutoGeneratedGetMemberValueProgressToNextLevel(object o)
      {
        return (object) ((Romance.RomanticState) o).ProgressToNextLevel;
      }

      internal static object AutoGeneratedGetMemberValueLastVisit(object o)
      {
        return (object) ((Romance.RomanticState) o).LastVisit;
      }

      internal static object AutoGeneratedGetMemberValueScoreFromPersuasion(object o)
      {
        return (object) ((Romance.RomanticState) o).ScoreFromPersuasion;
      }

      public Hero Partner(Hero hero)
      {
        if (this.Person1 == hero)
          return this.Person2;
        return this.Person2 == hero ? this.Person1 : (Hero) null;
      }
    }

    public enum RomanceLevelEnum
    {
      Ended = -2, // 0xFFFFFFFE
      Rejection = -1, // 0xFFFFFFFF
      Untested = 0,
      FailedInCompatibility = 1,
      FailedInPracticalities = 2,
      MatchMadeByFamily = 3,
      CourtshipStarted = 4,
      CoupleDecidedThatTheyAreCompatible = 5,
      CoupleAgreedOnMarriage = 6,
      Marriage = 7,
    }
  }
}
